using System;
using System.Collections.Generic;
using System.Text;
using Activa.CoolStorage;
using CodeStory.Gallery.ObjectEntity;

namespace CodeStory.Gallery.ObjectBusiness
{
	public sealed class GalleryFolderBusiness
	{
		private GalleryFolderBusiness() {

		}

		public static CSList<GalleryFolderObject> ListUserGalleryFolders(string userid,Guid currentuserid) {
			CSList<GalleryFolderObject> list;
			try {
				Guid id = new Guid(userid);
				if (id.Equals(currentuserid)) {
					list = GalleryFolderObject.List("UserID=@UserID", "@UserID", id);
				} else {
					list = GalleryFolderObject.List("UserID=@UserID And IsPub=1", "@UserID", id);
				}
			} catch {
				list = new CSList<GalleryFolderObject>();
			}
			return list;
		}

		public static void ToggleFolderPublic(string folderid) {
			Guid id = Guid.Empty;
			try {
				id = new Guid(folderid);
			} catch {
			}
			if (id.Equals(Guid.Empty)) return;
			GalleryFolderObject obj = GalleryFolderObject.Read(id);
			obj.IsPub = !obj.IsPub;
			obj.Save();
		}

		public static void DeleteGalleryFolder(string folderid) {
			Guid id = Guid.Empty;
			try {
				id = new Guid(folderid);
			} catch {
			}
			if (id.Equals(Guid.Empty)) return;
			GalleryFolderObject obj = GalleryFolderObject.Read(id);
			GalleryPhotoBusiness.DeletePhotosInFolder(obj.FolderID);
			obj.Delete();
		}

		public static void CreateFolder(string folderName, Guid userid) {
			GalleryFolderObject obj = GalleryFolderObject.New();
			obj.FolderID = Guid.NewGuid();
			obj.FolderName = folderName;
			obj.UserID = userid;
			obj.CreateDate = DateTime.Now;
			obj.CoverPhotoPath = "~/Images/Empty.jpg";
			obj.IsPub = false;
			obj.Save();
		}
	}
}
